package com.szholly.pro.watergas_server.ps.schedule;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;
import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.ps.service.TransValidationService;
import com.szholly.utils.util.StringUtils;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import lrq.common.MyLog;
/**
 *  定时任务，生成每周和每月的传输有效率数据
 * @author 熊伟
 *
 */
public class CreateTransValidationData  implements Job {
	static Logger log;
	
	@Autowired
	TransValidationService transValidationService;
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		
		if(log == null){
			log = MyLog.getLogger("CreateTransValidationData");
		}
		 
		try {
		   Calendar cal=Calendar.getInstance();
		   Calendar realCal = Calendar.getInstance();
		   //生成传输有效率周数据
		   realCal.setTime(cal.getTime());  
		   CreateWeekTransValidateData(realCal);
	       //生成传输有效率月数据
	       realCal.setTime(cal.getTime());  
	       CreateMonthTransValidateData(realCal);  
		   
		} catch (Exception e) {
			log.error("生成传输有效率数据出错",e);
		}
	}
	
	/**
	 * 
	 * 根据monitor_data_week中的均值数据，生成并插入相应的水质类别数据（week_water_type）
	 * xwei
	 * 2017年05月17日
	 * @return
	 * @throws ParseException 
	 */
	private void CreateWeekTransValidateData(Calendar cal){
		log.info("开始生成周数据");
		try{
			//判断当前时间是否为周一
	        if(cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY)
	        {
	        	return;
	        }
	        
	        //获取开始时间与结束时间
			Date endTime = cal.getTime();
			cal.add(Calendar.DAY_OF_MONTH, -7);
			Date startTime = cal.getTime();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
			SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			cal.setTime(endTime);
			cal.add(Calendar.DATE, -1);  //减1天
			
			String start = sdf.format(startTime);
			startTime = sdf.parse(start);
			
			endTime = cal.getTime();
			String end = sdf1.format(endTime);
			endTime = sdf2.parse(end);
			//设置周一为一周的开头,week=1时，应设置为53周
			cal.setFirstDayOfWeek(Calendar.MONDAY);
			int week = cal.get(Calendar.WEEK_OF_YEAR);
			if(week == 1)
			{
				week = 53;
			}
			CreateTransValidateData(startTime,endTime,"week");
		} catch(Exception e)
		{
			log.error("生成周数据出错",e);
		}
	}
	
	
	/**
	 * 
	 * 根据monitor_data_month中的均值数据，生成并插入相应的水质类别数据（month_water_type）
	 * xwei
	 * 2017年05月17日
	 * @return
	 * @throws ParseException 
	 */
	private void CreateMonthTransValidateData(Calendar cal){
		log.info("开始生成月数据");
		try{
			//判断当前时间是否为1号
	        if(cal.get(Calendar.DAY_OF_MONTH) != 1)
	        {
	        	return;
	        }
	        
	        //获取开始时间与结束时间
			Date endTime = cal.getTime();
			cal.add(Calendar.MONTH, -1);
			Date startTime = cal.getTime();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
			String start = sdf.format(startTime);
			startTime = sdf.parse(start);
			
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
			SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			cal.setTime(endTime);
			cal.add(Calendar.DATE, -1);  //减1天
			
			
			endTime = cal.getTime();
			String end = sdf1.format(endTime);
			endTime = sdf2.parse(end);
			
			CreateTransValidateData(startTime,endTime,"month");
		} catch(Exception e)
		{
			log.error("生成月数据出错",e);
		}
	}
	
	
	/**
	 * 生成数据
	 * xwei
	 * 2017年05月17日
	 */
	private void CreateTransValidateData(Date startTime,Date endTime,String cycleType)throws Exception{
		try{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			DecimalFormat decimalFormat=new DecimalFormat("#.00##");
			// 创建一个数值格式化对象  			  
	        NumberFormat numberFormat = NumberFormat.getInstance();  	  
	        // 设置精确到小数点后2位  	  
	        numberFormat.setMaximumFractionDigits(3);
			String start = sdf.format(startTime);
			String end = sdf.format(endTime);
			List<String> dataText = getM2MDateText(endTime,1,cycleType);
			
	        //传输率的计算
	        /**
	         * 第一步计算应收条数
	         */
	        //1.1 获取时间跨度
			String hours=getStationTime(start,end);
			int hoursInt=Integer.parseInt(hours);
			//1.2 几小时上传一条数据
			int hourInt=1;

			List<RowBase> stationIdList = getStationId();
			//1.3 获取站点参数数目
			if(stationIdList!=null && stationIdList.size()>0) {
				for(int K = 0;K<stationIdList.size();K++) {
					String id = stationIdList.get(K).getSafeString("CODE");
					List<RowBase> r=getpollParam(id);
					int m=r.size();
					//1.4 应收条数
					int RECEIVABLE_DATANUM=hoursInt*m/hourInt;
					/**
					 * 第二步计算实收条数
					 */
					//2.1 获取mn号
					String mn=r.get(0).getSafeString("DEVICE_NUM");
					//2.2 计算实收每个参数之和
					int REAL_DATANUM=0;//实收条数
					String parmname="";
					for(int i=0;i<r.size();i++){
						RowBase re=r.get(i);
						parmname+="'"+re.getSafeString("NAME")+"',";
					}
					parmname=parmname.substring(0,parmname.length()-1);
					REAL_DATANUM=getpollData(mn,parmname,start,end);
					
					//判断是否多传，实收不能大于应收
					if(REAL_DATANUM>RECEIVABLE_DATANUM){
						REAL_DATANUM=RECEIVABLE_DATANUM;
					}
					/**
					 * 计算停电时间段实收条数以及应收条数
					 */
					List<RowBase> noPowerList = getPowerOutageListByStation(startTime,endTime,id);
					int NOPOWER_REAL_DATANUM=0;
					int NOPOWER_RECEIVABLE_DATANUM=0;
					int NOPOWER_REALVALIDATE_PACKETNUM=0;
					int NOPOWER_RECEIVABLEVALIDATE_PACKETNUM=0;
					for(RowBase row:noPowerList)
					{
						String nopower_start = row.getSafeString("NO_POWER_START_TIME");
						String nopower_end = row.getSafeString("NO_POWER_END_TIME");
						Date s = sdf.parse(nopower_start);
						Date e = sdf.parse(nopower_end);
						nopower_start = sdf.format(s);
						nopower_end = sdf.format(e);
						if(s.compareTo(startTime)>=0&&e.compareTo(endTime)<=0)
						{
							//叠加应收的数据条数
							NOPOWER_RECEIVABLE_DATANUM+=Integer.parseInt(getStationTime(nopower_start,nopower_end))*m/hourInt;
							NOPOWER_RECEIVABLEVALIDATE_PACKETNUM+=Integer.parseInt(getStationTime(nopower_start,nopower_end))/hourInt;
							//叠加实收的数据条数
							NOPOWER_REAL_DATANUM+=getpollData(mn,parmname,nopower_start,nopower_end);
							NOPOWER_REALVALIDATE_PACKETNUM+=getValidData(mn,nopower_start,nopower_end);
						}
						else if(s.compareTo(startTime)<=0&&e.compareTo(endTime)<=0)
						{
							//叠加应收的数据条数
							NOPOWER_RECEIVABLE_DATANUM+=Integer.parseInt(getStationTime(sdf.format(startTime),nopower_end))*m/hourInt;
							NOPOWER_RECEIVABLEVALIDATE_PACKETNUM+=Integer.parseInt(getStationTime(sdf.format(startTime),nopower_end))/hourInt;
							//叠加实收的数据条数
							NOPOWER_REAL_DATANUM+=getpollData(mn,parmname,sdf.format(startTime),nopower_end);
							NOPOWER_REALVALIDATE_PACKETNUM+=getValidData(mn,sdf.format(startTime),nopower_end);
						}
						else if(s.after(startTime)&&e.after(endTime))
						{
							//叠加应收的数据条数
							NOPOWER_RECEIVABLE_DATANUM+=Integer.parseInt(getStationTime(nopower_start,sdf.format(endTime)))*m/hourInt;
							NOPOWER_RECEIVABLEVALIDATE_PACKETNUM+=Integer.parseInt(getStationTime(nopower_start,sdf.format(endTime)))/hourInt;
							//叠加实收的数据条数
							NOPOWER_REAL_DATANUM+=getpollData(mn,parmname,nopower_start,sdf.format(endTime));
							NOPOWER_REALVALIDATE_PACKETNUM+=getValidData(mn,nopower_start,sdf.format(endTime));
							
						}
						else
						{
							//叠加应收的数据条数
							NOPOWER_RECEIVABLE_DATANUM+=Integer.parseInt(getStationTime(sdf.format(startTime),sdf.format(endTime)))*m/hourInt;
							NOPOWER_RECEIVABLEVALIDATE_PACKETNUM+=Integer.parseInt(getStationTime(sdf.format(startTime),sdf.format(endTime)))/hourInt;
							//叠加实收的数据条数
							NOPOWER_REAL_DATANUM+=getpollData(mn,parmname,sdf.format(startTime),sdf.format(endTime));
							NOPOWER_REALVALIDATE_PACKETNUM+=getValidData(mn,sdf.format(startTime),sdf.format(endTime));
						}
					}
					REAL_DATANUM=REAL_DATANUM-NOPOWER_REAL_DATANUM;
					RECEIVABLE_DATANUM=RECEIVABLE_DATANUM-NOPOWER_RECEIVABLE_DATANUM;
					/**
					 * 第三步 计算传输率
					 */
					float rate=0;
					if(RECEIVABLE_DATANUM>0)
					{
							rate=Float.valueOf(numberFormat.format((float)REAL_DATANUM/(float)RECEIVABLE_DATANUM));
					}
					String TRANSFER_RATE=decimalFormat.format(rate);
					//有效率的计算
					/**
					 *第一步计算应收组数 
					 */
					int RECEIVABLEVALIDATE_PACKETNUM=hoursInt/hourInt;
					/**
					 * 第二步计算有效组数
					 */
					int REALVALIDATE_PACKETNUM=getValidData(mn,start,end);
					//计算流量为零的数据组数
					int invalidate_packetnum = getB01ZeroData(mn,start,end);
					//统计数据修约后 没有上传凭证的数据组数
					int unLoadCertificatePacketNum = getUnLoadCertificatePacketNum(mn,start,end);
					//有效组数不能大于应收组数
					if(REALVALIDATE_PACKETNUM>RECEIVABLEVALIDATE_PACKETNUM){
						REALVALIDATE_PACKETNUM=RECEIVABLEVALIDATE_PACKETNUM;
					}
					//获取停产停电故障时间产生的数据组数（这种情况要从实际有效组数中减去）
					int ERROR_PACKETNUM=0;
					
					//有效组数=实际应该有效数组个数-流量为0数组个数-修约后没有上传凭证的数据组数-停产停电时间段的数据组数
					REALVALIDATE_PACKETNUM = REALVALIDATE_PACKETNUM-invalidate_packetnum-ERROR_PACKETNUM-unLoadCertificatePacketNum;
					REALVALIDATE_PACKETNUM = REALVALIDATE_PACKETNUM-NOPOWER_REALVALIDATE_PACKETNUM;
					//可能会产生负数，负数的一律为0
					if(REALVALIDATE_PACKETNUM<0) {
						REALVALIDATE_PACKETNUM=0;
					}
					//停产停电的情况也要从应收数据组数中减去停电未传数据组数。
					RECEIVABLEVALIDATE_PACKETNUM = RECEIVABLEVALIDATE_PACKETNUM-ERROR_PACKETNUM-invalidate_packetnum;
					RECEIVABLEVALIDATE_PACKETNUM = RECEIVABLEVALIDATE_PACKETNUM-NOPOWER_RECEIVABLEVALIDATE_PACKETNUM;
					if(RECEIVABLEVALIDATE_PACKETNUM<0) {
						RECEIVABLEVALIDATE_PACKETNUM=0;
					}
					
					/**
					 * 第三步计算有效率
					 */
					float rateVali=0;
					if(RECEIVABLEVALIDATE_PACKETNUM>0)
					{
						rateVali=Float.valueOf(numberFormat.format((float)REALVALIDATE_PACKETNUM/(float)RECEIVABLEVALIDATE_PACKETNUM));
					}
					String VALIDATE_RATE=decimalFormat.format(rateVali);
					//传输有效率计算
					float rateAll=rate*rateVali;
					String Allrate=decimalFormat.format(rateAll);
					
					
					String insertSql ="insert into data_trans_validation\n" +
									"  (guid, station_id, data_text, real_datanum, receivable_datanum, transfer_rate, receivablevalidate_packetnum, realvalidate_packetnum, validate_rate, transfer_validate_rate)\n" + 
									"values\n" + 
									"  (sys_guid(), @STATION_ID, @v_data_text, @v_real_datanum, @v_receivable_datanum, @v_transfer_rate, @v_receivablevalidate_packetnum, @v_realvalidate_packetnum, @v_validate_rate, @v_transfer_validate_rate)";

					List<GlobalParameter> parms = new ArrayList<>();
					parms.add(new GlobalParameter("STATION_ID", id));
					parms.add(new GlobalParameter("v_data_text", dataText.get(0)));
					parms.add(new GlobalParameter("v_real_datanum", REAL_DATANUM));
					parms.add(new GlobalParameter("v_receivable_datanum", RECEIVABLE_DATANUM));
					parms.add(new GlobalParameter("v_transfer_rate", TRANSFER_RATE));
					parms.add(new GlobalParameter("v_receivablevalidate_packetnum", RECEIVABLEVALIDATE_PACKETNUM));
					parms.add(new GlobalParameter("v_realvalidate_packetnum", REALVALIDATE_PACKETNUM));
					parms.add(new GlobalParameter("v_validate_rate", VALIDATE_RATE));
					parms.add(new GlobalParameter("v_transfer_validate_rate", Allrate));
					try{
						DataUtil.ExecuteUpdateSql(insertSql, parms);
					}catch(Exception e){
						e.printStackTrace();
					}
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取环比时间点集
	 * gislin
	 * 2016年8月27日
	 * @param endDate
	 * @param dateLength
	 * @param cycleTypeStr day,week,month,quarter,year
	 * @return
	 * @throws ParseException
	 */
	private List<String> getM2MDateText(Date endDate,int dateLength,String cycleTypeStr) throws ParseException{
		
		List<String> dateTexts = new ArrayList<>();
		List<String> resultDateTexts = new ArrayList<>();
		
		Calendar currentCal = Calendar.getInstance();
		currentCal.setTime(endDate);
		
		//如果是季度的话，把月置为每个季度的第一个月
		if("quarter".equals(cycleTypeStr)){
			int month = currentCal.get(Calendar.MONTH);
			if(month <= 3){
				currentCal.set(Calendar.MONTH, 1);
			}
			else if(month <= 6){
				currentCal.set(Calendar.MONTH, 4);
			}
			else if(month <= 9){
				currentCal.set(Calendar.MONTH, 7);
			}
			else if(month <= 12){
				currentCal.set(Calendar.MONTH, 10);
			}
		}
		
		for(int i=0;i<dateLength;i++){
			
			int year = currentCal.get(Calendar.YEAR);
			int week = currentCal.get(Calendar.WEEK_OF_YEAR);
			
			String curMonth = "";
			if("week".equals(cycleTypeStr)){
				dateTexts.add(year + "年" + week+"周");
				currentCal.add(Calendar.WEEK_OF_YEAR, -1);
			}
			else if("month".equals(cycleTypeStr)){
				curMonth = String.format("%0" + 2 + "d", currentCal.get(Calendar.MONTH)+1);
				dateTexts.add(year + "年" + curMonth+"月");
				currentCal.add(Calendar.MONTH, -1);
			}
		}
		for(int i=dateTexts.size()-1;i>=0;i--){
			resultDateTexts.add(dateTexts.get(i));
		}
		
		return resultDateTexts;
	}
	
	/**
	 * 获取站点运行时间，默认站点24小时都在运行
	 * @param st 开始时间
	 * @param et 结束时间
	 * @return
	 */
	public String getStationTime(String st,String et){
		//一小时有多少毫秒
		 long nh = 1000 * 60 * 60;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date ct_date=new Date ();
		Date et_date=new Date();
		try {
			ct_date = sdf.parse(st);
			et_date = sdf.parse(et);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		// 获得两个时间的毫秒时间差异
	    long diff = et_date.getTime() - ct_date.getTime();
	    // 计算差多少小时
	    long counthour = diff / nh;
	    //如果是23:59:59就加1
	    if(et.contains("23:59:59")){
	    	counthour=counthour+1;
	    }
	    return counthour+"";
	}
	
	/**
	 * 获取站点参数
	 * @param stationId
	 * @return
	 */
	public List<RowBase> getpollParam(String stationId){
		String sql="select t.name,t1.device_num,t.site_id from BC_SITE_POLL t left join BC_COLLECTION_INFO t1 on t.site_id=t1.site_id where t.site_id='"+stationId+"' group by t.name,t1.device_num,t.site_id";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> row = DataUtil.getSelectRows(sql, parms);
		return row;
	}
	
	/**
	 * 获取时间段内参数条数
	 * @param mn
	 * @param parmname
	 * @param st
	 * @param et
	 * @return
	 */
	public int getpollData(String mn,String parmname,String st ,String et){
		String sql="select t.*  from BD_MO_HOUR t where t.mn='"+mn+"' and t.parmname in ("+parmname+") and t.datatime >= to_date('"
				   +st+"','yyyy-MM-dd hh24:mi:ss') and t.datatime <= to_date('"+et+"','yyyy-MM-dd hh24:mi:ss')";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> row = DataUtil.getSelectRows(sql, parms);
		return row.size();
	}

	/**
	 * 获取有效组数()
	 * @param mn
	 * @param st
	 * @param et
	 * @return
	 */
	public int getValidData(String mn,String st ,String et){
		String sql="select count(*) as sum  from (select distinct (t.mn||to_char(t.datatime,'yyyy-MM-dd HH24:mi:ss')) as guid from BD_MO_HOUR t where t.flag ='N' and t.mn='"+mn+"' and t.datatime >= to_date('"
				   +st+"','yyyy-MM-dd hh24:mi:ss') and t.datatime <= to_date('"+et+"','yyyy-MM-dd hh24:mi:ss'))";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> row = DataUtil.getSelectRows(sql, parms);
		int result=0;
		if(row.size()>0){
			result=row.get(0).getSafeInt("SUM");
		}
		return result;
	}
	/**
	 * 获取流量为0的数据条数
	 * @param mn
	 * @param st
	 * @param et
	 * @return
	 */
	private int getB01ZeroData(String mn,String st ,String et){
		String pollSql = "select t2.name\n" +
						"  from bc_collection_info t\n" + 
						"  left join bc_site_poll t2 on t.site_id = t2.site_id\n" + 
						" where t.device_num = '"+mn+"'";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> pollrow = DataUtil.getSelectRows(pollSql, parms);
		//调整流量筛选策略，如果该站点有瞬时流量，则根据瞬时流量来统计流量为0的条数，否则根据累计流量统计
		String paramName="B01TOTAL";
		if(pollrow!=null && pollrow.size()>0) {
			for(int i = 0;i < pollrow.size();i++) {
				RowBase row = new RowBase();
				row = pollrow.get(i);
				String pollName = row.getSafeString("NAME");
				if("B01".equals(pollName)){
					paramName = "B01";
					break;
				}
			}
		}
		String sql="select t.parmname,t.datatime,t.avg  from  bd_mo_hour t where t.flag ='N' and t.mn='"+mn+"' and t.datatime >= to_date('\n"
				   +st+"','yyyy-MM-dd hh24:mi:ss') and t.datatime <= to_date('"+et+"','yyyy-MM-dd hh24:mi:ss') \n"
				   + " and t.avg=0 and t.parmname='"+paramName+"'\n"
				   + " group by t.parmname,t.datatime,t.avg";
		List<RowBase> row = DataUtil.getSelectRows(sql, parms);
		int result=0;
		if(row.size()>0){
			result=row.size();
		}
		return result;
	}
	
	/***
	 * 根据故障时间计算缺失数据组数
	 * @param mn
	 * @param st
	 * @param et
	 * @return
	 * @throws ParseException 
	 */
	public int getHoursDistance(String errorStartTime,String errorEndTime) throws ParseException{
		int hours=0;
		if(StringUtils.IsNullOrEmpty(errorStartTime) ||StringUtils.IsNullOrEmpty(errorEndTime)) {
			return hours;
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date start = dateFormat.parse(errorStartTime);
		Date end =dateFormat.parse(errorEndTime);
		if(start.after(end)) {
			return hours;
		}
		long StartMills = start.getTime();
		long EndMills = end.getTime();
		long startHours = StartMills/(3600*1000);
		long endHours = EndMills/(3600*1000);
		long millsDistance = EndMills-StartMills;
		if(millsDistance>0 && millsDistance<=3600000) {
			hours=1;
		} else {
			hours = (int)Math.ceil(endHours-startHours);
		}
		
		return hours;
	}
	
	/**
	 * 获取修约后未上传凭证的数据组数
	 * @param mn
	 * @param st
	 * @param et
	 * @return
	 */
	public int getUnLoadCertificatePacketNum(String mn,String st ,String et){
		String sql="select t.datatime  from  BD_MO_HOUR t where t.flag ='N' and t.mn='"+mn+"' and t.datatime >= to_date('\n"
				   +st+"','yyyy-MM-dd hh24:mi:ss') and t.datatime <= to_date('"+et+"','yyyy-MM-dd hh24:mi:ss') \n"+
				   " and t.data_from>0 and t.modify_certificate_id is null \n"+
				   " and t.modify_date is not null \n"+
				   " group by t.datatime ";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> row = DataUtil.getSelectRows(sql, parms);
		int result=0;
		if(row.size()>0){
			result=row.size();
		}
		return result;
	}
	
	/**
	 * 获取站点参数(获取污染源所有站点ID)
	 * @param stationId
	 * @return
	 */
	public List<RowBase> getStationId(){
		String sql="select t.code from BC_SITE_INFO t  where t.station_category in ('4')";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> row = DataUtil.getSelectRows(sql, parms);
		return row;
	}
	public List<RowBase> getPowerOutageListByStation(Date start,Date end,String stationID)
	{
	    String querySql="select *  from BC_SNP_INFO t where t.station_id=@station_id \n"
	    		+" and  t.no_power_start_time <=@endDate\n"
	    		+" and  t.no_power_end_time >=@startDate\n";
	    querySql+=" order by t.no_power_start_time";
	    
		List<GlobalParameter> parms = new ArrayList<>();
		parms.add(new GlobalParameter("station_id", stationID));
		parms.add(new GlobalParameter("startDate", start));
		parms.add(new GlobalParameter("endDate", end));
	    List<RowBase> result = DataUtil.getSelectRows(querySql, parms);
	    return result;
	}
}
